package cn.like.backEnd.biz.service.impl;

import cn.like.backEnd.biz.mapper.AuthUserMapper;
import cn.like.backEnd.biz.service.AuthUserService;
import cn.like.common.dto.SignInRequestDto;
import cn.like.entity.AuthUser;
import cn.like.util.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 用户(AuthUser)表服务实现类
 *
 * @author like
 * @since 2021-07-08 15:31:25
 */
@Service
public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, AuthUser> implements AuthUserService {

    @Override
    public AuthUser findByAccount(String account) {
        return getBaseMapper().findByAccount(account);
    }

    @Override
    public AuthUser findByAccountOrName(String account, String name) {
        return this.getOne(this.lambdaQuery().eq(AuthUser::getAccount, account).or().eq(AuthUser::getName, name));
    }

    @Override
    public AuthUser createAuthUser(SignInRequestDto signInRequestDto) {
        final AuthUser user = BeanUtil.copy(signInRequestDto, new AuthUser());

        user.insert();

        return user;
    }
}